﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
namespace Entity
{
    public class ReturnCommon
    {
        public static ReturnInfo ReturnErrMessage(string Message, params object[] args)
        {
            ReturnInfo info = new ReturnInfo();
            info.Message = string.Format(Message, args);
            info.State = false;
            info.Data = new List<string>();
            return info;
        }

        public static ReturnInfo ReturnMessage(string Message, bool State, IList<string> Data)
        {
            ReturnInfo info = new ReturnInfo();
            info.Message = Message;
            info.State = State;
            info.Data = Data;
            return info;
        }

        public static ReturnInfo ReturnSucceedMessage(string Message)
        {
            ReturnInfo info = new ReturnInfo();
            info.Message = Message;
            info.State = true;
            info.Data = new List<string>();
            return info;
        }

        public static string ReturnTextJsonErrMessage(string Message, params object[] args)
        {
            return ReturnTextJsonMessage(string.Format(Message, args), false, new List<string>()).TrimEnd("\0".ToCharArray());
        }

        public static string ReturnTextJsonMessage(string Message, bool State, IList<string> Data)
        {
            ReturnInfo inputData = new ReturnInfo();
            inputData.Message = Message;
            inputData.State = State;
            inputData.Data = Data;
            return SerializerToJson(inputData);
        }

        public static string ReturnTextJsonSucceedMessage(string Message)
        {
            ReturnInfo inputData = new ReturnInfo();
            inputData.Message = Message;
            inputData.State = true;
            inputData.Data = new List<string>();
            return SerializerToJson(inputData).TrimEnd("\0".ToCharArray());
        }

        public static string SerializerToJson(object InputData)
        {
            StringBuilder output = new StringBuilder();
            new JavaScriptSerializer().Serialize(InputData, output);
            return output.ToString();
        }

    }
}
